<%@ page import="com.ld.businesscard_manage.service.BusinessCardService" %>
<%@ page import="com.ld.businesscard_manage.service.impl.BusinessCardServiceImpl" %>
<%@ page import="com.ld.businesscard_manage.bean.BusinessCard" %>
<%@ page import="java.util.List" %>
<%@ page import="com.ld.businesscard_manage.bean.User" %><%--
  Created by IntelliJ IDEA.
  User: 刘邓
  Date: 2023-06-10
  Time: 19:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>条件名片管理</title>
</head>
<body>
<%!
    private BusinessCardService businessCardService = new BusinessCardServiceImpl();
%>
<%
    String name = request.getParameter("name");
	User usr = (User)(session.getAttribute("user"));
    List<BusinessCard> cards = businessCardService.getMyCardsByLike(name,usr.getUsername());
    out.println("<a href='/home/application.jsp' style='display: inline-block;width:30%,height: 30px;margin:10px 30px;text-align:center;line-height:30px;background-color:blue'>返回个人页面</a><br>");
    out.println("<a href='/home/addMyCard.jsp' style='display: inline-block;width:30%,height: 30px;margin:10px 30px;text-align:center;line-height:30px;background-color:orange'>添加名片</a>");
    if (cards.isEmpty()) out.println("<h1 style='width: 80%;height:400px;margin: 0 auto;text-align:center;line-height:400px'>暂无更多信息!<h1>");
	else {
        out.println("<table style='width:80%;height:400px;margin:0 auto; border:1px solid #ccc;cellspacing:0; cellpadding:0'>" +
                "<tr>" +
                "<th>姓名</th>" +
                "<th>性别</th>" +
                "<th>邮箱</th>" +
                "<th>状态</th>" +
                "<th>修改</th>" +
                "<th>放入回收站</th>" +
                "<th>永久删除</th>" +
                "</tr>");
        for (BusinessCard card : cards) {
            int sex0 = card.getSex();
            String sex;
            if (sex0 == 0) {
                sex = "男";
            } else {
                sex = "女";
            }
            int valid0 = card.getValid();
            String valid;
            if (valid0 == 0) {
                valid = "正在使用";
            } else if (valid0 == 1) {
                valid = "待删除";
            } else {
                valid = "已删除";
            }
            String changeDOM = "<td><a href=" + "'/home/changeMyCard.jsp?id=" + card.getId() + "'>修改" + "</a></td>";
            String deleteDOM = "<td><a href=" + "'/home/deleteCard.jsp?id=" + card.getId() + "'>回收站" + "</a></td>";
            String deletedDOM = "<td><a href=" + "'/home/deletedCard.jsp?id=" + card.getId() + "'>永久删除" + "</a></td>";
            out.println("<tr>");
            out.println("<td style='text-align:center'>" + card.getName() + "</td>");
            out.println("<td style='text-align:center'>" + sex + "</td>");
            out.println("<td style='text-align:center'>" + card.getEmail() + "</td>");
            out.println("<td style='text-align:center'>" + valid + "</td>");
            out.println(changeDOM);
            out.println(deleteDOM);
            out.println(deletedDOM);
            out.println("</tr>");
        }
        out.println("</table>");
    }

%>
</body>
</html>
